package Problem;

import java.math.BigInteger;

public class 幸运数字 {
	public static void main(String[] args) {
		int num = 0;
		for (int i = 1; num <= 2023 ; i++) {
			if(i % getTotal(Integer.toBinaryString(i)) != 0) {
				continue;
			}else if (i % getTotal(Integer.toOctalString(i)) != 0) {
				continue;
			}else if(i % getTotal(String.valueOf(i)) != 0){
				continue;
			}else if(i % getTotal(Integer.toHexString(i))!=0){
				continue;
			}
			num++;
			if(num == 2023) {
				System.out.println(i);
				break;
			}
		}
	}

	private static int getTotal(String str) {
		int total = 0;
		char[] arr= {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
		for (int i = 0; i < str.length(); i++) {
			for (int j = 0; j < arr.length; j++) {
				if(str.charAt(i) == arr[j]) {
					total += j;
					break;
				}
			}
		}
		return total;
	}
}
